package cn.xiaoliu.user.controller;

import cn.xiaoliu.basic.exception.BusinessException;
import cn.xiaoliu.basic.utils.AjaxResult;
import cn.xiaoliu.org.domain.Shop;
import cn.xiaoliu.user.dto.UserDto;
import cn.xiaoliu.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    /**
     * 手机注册
     * @param dto
     * @return
     */
    @PostMapping("/phone/register")
    public AjaxResult register(@RequestBody UserDto dto){
        try {
            userService.register(dto);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me()
                    .setSuccess(false)
                    .setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me()
                    .setSuccess(false)
                    .setMessage("业务繁忙，稍后重试");
        }
    }
}
